package com.cnctema.easecalendar_weekly_view.database

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase

/**
 * @ClassName: EventDatabase
 * @Description: 日历事件数据库(类的作用描述)
 * @Author: cnctema
 * @CreateDate: 2020/5/26 2:47
 */
@Database(
    entities = [Event::class],
    version = 1,
    exportSchema = false
)
abstract class EventDatabase : RoomDatabase() {
    abstract val eventDatabaseDao : EventDatabaseDao

    companion object{
        @Volatile
        private var INSANCE: EventDatabase? = null

        fun getInstance(context: Context): EventDatabase {
            synchronized(this){
                var instant = INSANCE
                if(instant == null){
                    instant = Room.databaseBuilder(
                        context.applicationContext,
                        EventDatabase::class.java,
                        "event_database"
                    ).fallbackToDestructiveMigration().build()
                    INSANCE = instant
                }
                return instant
            }
        }
    }
}
